#!/bin/sh

function get_partition_dev()
{
	mtdblockid=`cat /proc/mtd | grep -E "\"$1\"$" | grep -E -o "mtd[0-9]+" | grep -E -o "[0-9]+"`
	if [ "$mtdblockid" != "" ];then
		echo "/dev/mtdblock$mtdblockid"
	else
		echo ""
	fi
}

# mount usr file-system.
#/bin/mount -t squashfs /dev/mtdblock7 /usr
partition_app=`get_partition_dev APP`
if [ "$partition_app" != "" ];then
	echo "/bin/mount -t squashfs $partition_app /usr"
	/bin/mount -t squashfs $partition_app /usr
fi

# mount jffs2 file-system.
#/bin/mount -t jffs2 /dev/mtdblock6 /etc/config
partition_config=`get_partition_dev CONFIG`
if [ "$partition_config" != "" ];then
	echo "/bin/mount -t jffs2 $partition_config /etc/config"
	/bin/mount -t jffs2 $partition_config /etc/config
fi

echo "starting mdev..."
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s

# note: can't recommend running other app before `mount` command.

ifconfig lo 127.0.0.1

#start system service
/usr/sbin/main.sh &
